/**
 * 案例模型
 */

import {
  Entity,
  Column,
  CreateDateColumn,
  OneToOne,
  JoinColumn,
  ManyToMany,
  JoinTable,
  PrimaryColumn
} from "typeorm";
import { BblAttach } from "./attach.entity";

@Entity("BBL_CASE")
export class BblCase {
  /**
   * 案例id
   */
  @PrimaryColumn({
    name: "CASE_ID",
    type: "varchar",
    length: 50,
    comment: "案例ID"
  })
  caseId: string;

  /**
   * 案例主标题
   */
  @Column({
    name: "CASE_MAIN_TITLE",
    type: "varchar",
    length: 255,
    comment: "案例主标题"
  })
  caseMainTitle: string;

  /**
   * 案例副标题
   */
  @Column({
    name: "CASE_SUB_TITLE",
    type: "varchar",
    length: 255,
    comment: "案例副标题"
  })
  caseSubTitle: string;

  /**
   * 封面图片
   */
  @OneToOne((type) => BblAttach, { createForeignKeyConstraints: false })
  @JoinColumn({
    name: "CASE_COVER_ATT_ID",
    referencedColumnName: "attId"
  })
  caseCoverImg: BblAttach;

  /**
   * 案例主图
   */
  @ManyToMany((type) => BblAttach, { createForeignKeyConstraints: false })
  @JoinTable({
    name: "BBL_CASE_MAIN_IMG",
    joinColumn: {
      name: "CASE_ID",
      referencedColumnName: "caseId"
    },
    inverseJoinColumn: {
      name: "ATT_ID",
      referencedColumnName: "attId"
    }
  })
  caseMainImgs: BblAttach[];

  /**
   * 案例描述
   */
  @Column({
    name: "CASE_TEXT",
    type: "text",
    comment: "案例描述"
  })
  caseText: string;

  @CreateDateColumn({
    type: "timestamp",
    name: "CREATE_AT"
  })
  createAt: Date;
}
